package mytankGame02;

public class Shot implements Runnable{
    int x;
    int y;
    int speed = 1;
    int direction;
    boolean is_alive = true;


    public Shot(int x, int y, int direction) {
        this.x = x;
        this.y = y;
        this.direction = direction;
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public void setDirection(int direction) {
        this.direction = direction;
    }

    public void setIs_alive(boolean is_alive) {
        this.is_alive = is_alive;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public int getSpeed() {
        return speed;
    }

    public int getDirection() {
        return direction;
    }

    public boolean isIs_alive() {
        return is_alive;
    }

    @Override
    public void run() {
        while(true){
            switch(direction){
                case 0:
                    y -= speed;
                    break;
                case 1:
                    x += speed;
                    break;
                case 2:
                    y += speed;
                    break;
                case 3:
                    x -= speed;
                    break;
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if(!(x > 0 && x < 1000 && y > 0 && y < 750 && is_alive)){
                is_alive = false;
                break;
            }
            System.out.println("x="+ x+", y="+ y);
        }

    }
}
